<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Box2D: b2Math.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="icon.gif"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Box2D
   &#160;<span id="projectnumber">2.2.1</span>
   </div>
   <div id="projectbrief">A 2D Physics Engine for Games</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">b2Math.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org</span>
<a name="l00003"></a>00003 <span class="comment">*</span>
<a name="l00004"></a>00004 <span class="comment">* This software is provided &#39;as-is&#39;, without any express or implied</span>
<a name="l00005"></a>00005 <span class="comment">* warranty.  In no event will the authors be held liable for any damages</span>
<a name="l00006"></a>00006 <span class="comment">* arising from the use of this software.</span>
<a name="l00007"></a>00007 <span class="comment">* Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00008"></a>00008 <span class="comment">* including commercial applications, and to alter it and redistribute it</span>
<a name="l00009"></a>00009 <span class="comment">* freely, subject to the following restrictions:</span>
<a name="l00010"></a>00010 <span class="comment">* 1. The origin of this software must not be misrepresented; you must not</span>
<a name="l00011"></a>00011 <span class="comment">* claim that you wrote the original software. If you use this software</span>
<a name="l00012"></a>00012 <span class="comment">* in a product, an acknowledgment in the product documentation would be</span>
<a name="l00013"></a>00013 <span class="comment">* appreciated but is not required.</span>
<a name="l00014"></a>00014 <span class="comment">* 2. Altered source versions must be plainly marked as such, and must not be</span>
<a name="l00015"></a>00015 <span class="comment">* misrepresented as being the original software.</span>
<a name="l00016"></a>00016 <span class="comment">* 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00017"></a>00017 <span class="comment">*/</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#ifndef B2_MATH_H</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define B2_MATH_H</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;<a class="code" href="b2_settings_8h.html">Box2D/Common/b2Settings.h</a>&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;cmath&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;cfloat&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;cstddef&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;limits&gt;</span>
<a name="l00028"></a>00028 
<a name="l00031"></a>00031 <span class="keyword">inline</span> <span class="keywordtype">bool</span> b2IsValid(float32 x)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033         <span class="keywordflow">if</span> (x != x)
<a name="l00034"></a>00034         {
<a name="l00035"></a>00035                 <span class="comment">// NaN.</span>
<a name="l00036"></a>00036                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00037"></a>00037         }
<a name="l00038"></a>00038 
<a name="l00039"></a>00039         float32 infinity = std::numeric_limits&lt;float32&gt;::infinity();
<a name="l00040"></a>00040         <span class="keywordflow">return</span> -infinity &lt; x &amp;&amp; x &lt; infinity;
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042 
<a name="l00044"></a>00044 <span class="keyword">inline</span> float32 b2InvSqrt(float32 x)
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046         <span class="keyword">union</span>
<a name="l00047"></a>00047         {
<a name="l00048"></a>00048                 float32 x;
<a name="l00049"></a>00049                 int32 i;
<a name="l00050"></a>00050         } convert;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052         convert.x = x;
<a name="l00053"></a>00053         float32 xhalf = 0.5f * x;
<a name="l00054"></a>00054         convert.i = 0x5f3759df - (convert.i &gt;&gt; 1);
<a name="l00055"></a>00055         x = convert.x;
<a name="l00056"></a>00056         x = x * (1.5f - xhalf * x * x);
<a name="l00057"></a>00057         <span class="keywordflow">return</span> x;
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="preprocessor">#define b2Sqrt(x)       std::sqrt(x)</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define b2Atan2(y, x)   std::atan2(y, x)</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span>
<a name="l00064"></a><a class="code" href="structb2_vec2.html">00064</a> <span class="keyword">struct </span><a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>
<a name="l00065"></a>00065 {
<a name="l00067"></a><a class="code" href="structb2_vec2.html#a9171b31deb83af96872f99689939a12f">00067</a>         <a class="code" href="structb2_vec2.html#a9171b31deb83af96872f99689939a12f" title="Default constructor does nothing (for performance).">b2Vec2</a>() {}
<a name="l00068"></a>00068 
<a name="l00070"></a><a class="code" href="structb2_vec2.html#aa8a2f026420a84bbbc62f3a3de2041d6">00070</a>         <a class="code" href="structb2_vec2.html#aa8a2f026420a84bbbc62f3a3de2041d6" title="Construct using coordinates.">b2Vec2</a>(float32 x, float32 y) : x(x), y(y) {}
<a name="l00071"></a>00071 
<a name="l00073"></a><a class="code" href="structb2_vec2.html#a5c6cbe27cfb29c6dbb29b9a3285b88d0">00073</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec2.html#a5c6cbe27cfb29c6dbb29b9a3285b88d0" title="Set this vector to all zeros.">SetZero</a>() { x = 0.0f; y = 0.0f; }
<a name="l00074"></a>00074 
<a name="l00076"></a><a class="code" href="structb2_vec2.html#a4d61640a645e470a50b451307d8e94c3">00076</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec2.html#a4d61640a645e470a50b451307d8e94c3" title="Set this vector to some specified coordinates.">Set</a>(float32 x_, float32 y_) { x = x_; y = y_; }
<a name="l00077"></a>00077 
<a name="l00079"></a><a class="code" href="structb2_vec2.html#ab1f648091d3cba00b4c132758fcf4450">00079</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_vec2.html#ab1f648091d3cba00b4c132758fcf4450" title="Negate this vector.">operator -</a>()<span class="keyword"> const </span>{ <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> v; v.<a class="code" href="structb2_vec2.html#a4d61640a645e470a50b451307d8e94c3" title="Set this vector to some specified coordinates.">Set</a>(-x, -y); <span class="keywordflow">return</span> v; }
<a name="l00080"></a>00080         
<a name="l00082"></a><a class="code" href="structb2_vec2.html#a9cb67b5f755b82d40673337a3652d81f">00082</a>         float32 <a class="code" href="structb2_vec2.html#a9cb67b5f755b82d40673337a3652d81f" title="Read from and indexed element.">operator () </a>(int32 i)<span class="keyword"> const</span>
<a name="l00083"></a>00083 <span class="keyword">        </span>{
<a name="l00084"></a>00084                 <span class="keywordflow">return</span> (&amp;x)[i];
<a name="l00085"></a>00085         }
<a name="l00086"></a>00086 
<a name="l00088"></a><a class="code" href="structb2_vec2.html#a50b39580d9f479e17b23ce3cb8efbac6">00088</a>         float32&amp; <a class="code" href="structb2_vec2.html#a9cb67b5f755b82d40673337a3652d81f" title="Read from and indexed element.">operator () </a>(int32 i)
<a name="l00089"></a>00089         {
<a name="l00090"></a>00090                 <span class="keywordflow">return</span> (&amp;x)[i];
<a name="l00091"></a>00091         }
<a name="l00092"></a>00092 
<a name="l00094"></a><a class="code" href="structb2_vec2.html#a590789342e22ac1e7f9c1a63a2778b6d">00094</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec2.html#a590789342e22ac1e7f9c1a63a2778b6d" title="Add a vector to this vector.">operator += </a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00095"></a>00095         {
<a name="l00096"></a>00096                 x += v.x; y += v.y;
<a name="l00097"></a>00097         }
<a name="l00098"></a>00098         
<a name="l00100"></a><a class="code" href="structb2_vec2.html#a6b48cab4695a979ae40b7613aedc8b17">00100</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec2.html#a6b48cab4695a979ae40b7613aedc8b17" title="Subtract a vector from this vector.">operator -= </a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00101"></a>00101         {
<a name="l00102"></a>00102                 x -= v.x; y -= v.y;
<a name="l00103"></a>00103         }
<a name="l00104"></a>00104 
<a name="l00106"></a><a class="code" href="structb2_vec2.html#a7097696dce578322928f4535b34f1c6b">00106</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec2.html#a7097696dce578322928f4535b34f1c6b" title="Multiply this vector by a scalar.">operator *= </a>(float32 a)
<a name="l00107"></a>00107         {
<a name="l00108"></a>00108                 x *= a; y *= a;
<a name="l00109"></a>00109         }
<a name="l00110"></a>00110 
<a name="l00112"></a><a class="code" href="structb2_vec2.html#afb1c498214b88874fcb07eb6322374da">00112</a>         float32 <a class="code" href="structb2_vec2.html#afb1c498214b88874fcb07eb6322374da" title="Get the length of this vector (the norm).">Length</a>()<span class="keyword"> const</span>
<a name="l00113"></a>00113 <span class="keyword">        </span>{
<a name="l00114"></a>00114                 <span class="keywordflow">return</span> b2Sqrt(x * x + y * y);
<a name="l00115"></a>00115         }
<a name="l00116"></a>00116 
<a name="l00119"></a><a class="code" href="structb2_vec2.html#af66641b887488490e2168bfafc5a7e36">00119</a>         float32 <a class="code" href="structb2_vec2.html#af66641b887488490e2168bfafc5a7e36">LengthSquared</a>()<span class="keyword"> const</span>
<a name="l00120"></a>00120 <span class="keyword">        </span>{
<a name="l00121"></a>00121                 <span class="keywordflow">return</span> x * x + y * y;
<a name="l00122"></a>00122         }
<a name="l00123"></a>00123 
<a name="l00125"></a><a class="code" href="structb2_vec2.html#adda78c92f318fe53d8a53f9b5cfd8e41">00125</a>         float32 <a class="code" href="structb2_vec2.html#adda78c92f318fe53d8a53f9b5cfd8e41" title="Convert this vector into a unit vector. Returns the length.">Normalize</a>()
<a name="l00126"></a>00126         {
<a name="l00127"></a>00127                 float32 length = <a class="code" href="structb2_vec2.html#afb1c498214b88874fcb07eb6322374da" title="Get the length of this vector (the norm).">Length</a>();
<a name="l00128"></a>00128                 <span class="keywordflow">if</span> (length &lt; b2_epsilon)
<a name="l00129"></a>00129                 {
<a name="l00130"></a>00130                         <span class="keywordflow">return</span> 0.0f;
<a name="l00131"></a>00131                 }
<a name="l00132"></a>00132                 float32 invLength = 1.0f / length;
<a name="l00133"></a>00133                 x *= invLength;
<a name="l00134"></a>00134                 y *= invLength;
<a name="l00135"></a>00135 
<a name="l00136"></a>00136                 <span class="keywordflow">return</span> length;
<a name="l00137"></a>00137         }
<a name="l00138"></a>00138 
<a name="l00140"></a><a class="code" href="structb2_vec2.html#aafb971cf7cc726f91fc3a8215fb0aa17">00140</a>         <span class="keywordtype">bool</span> <a class="code" href="structb2_vec2.html#aafb971cf7cc726f91fc3a8215fb0aa17" title="Does this vector contain finite coordinates?">IsValid</a>()<span class="keyword"> const</span>
<a name="l00141"></a>00141 <span class="keyword">        </span>{
<a name="l00142"></a>00142                 <span class="keywordflow">return</span> b2IsValid(x) &amp;&amp; b2IsValid(y);
<a name="l00143"></a>00143         }
<a name="l00144"></a>00144 
<a name="l00146"></a><a class="code" href="structb2_vec2.html#a8f2c6e60cb5898bc239801bd19e2d619">00146</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_vec2.html#a8f2c6e60cb5898bc239801bd19e2d619" title="Get the skew vector such that dot(skew_vec, other) == cross(vec, other)">Skew</a>()<span class="keyword"> const</span>
<a name="l00147"></a>00147 <span class="keyword">        </span>{
<a name="l00148"></a>00148                 <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html#a9171b31deb83af96872f99689939a12f" title="Default constructor does nothing (for performance).">b2Vec2</a>(-y, x);
<a name="l00149"></a>00149         }
<a name="l00150"></a>00150 
<a name="l00151"></a>00151         float32 x, y;
<a name="l00152"></a>00152 };
<a name="l00153"></a>00153 
<a name="l00155"></a><a class="code" href="structb2_vec3.html">00155</a> <span class="keyword">struct </span><a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>
<a name="l00156"></a>00156 {
<a name="l00158"></a><a class="code" href="structb2_vec3.html#a837423f66d6fb72d815e7390c09938b9">00158</a>         <a class="code" href="structb2_vec3.html#a837423f66d6fb72d815e7390c09938b9" title="Default constructor does nothing (for performance).">b2Vec3</a>() {}
<a name="l00159"></a>00159 
<a name="l00161"></a><a class="code" href="structb2_vec3.html#a47df55b26ab254dcf42a16638c7feeeb">00161</a>         <a class="code" href="structb2_vec3.html#a47df55b26ab254dcf42a16638c7feeeb" title="Construct using coordinates.">b2Vec3</a>(float32 x, float32 y, float32 z) : x(x), y(y), z(z) {}
<a name="l00162"></a>00162 
<a name="l00164"></a><a class="code" href="structb2_vec3.html#a5a459ed49f1910a347ca247f848a2dd8">00164</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec3.html#a5a459ed49f1910a347ca247f848a2dd8" title="Set this vector to all zeros.">SetZero</a>() { x = 0.0f; y = 0.0f; z = 0.0f; }
<a name="l00165"></a>00165 
<a name="l00167"></a><a class="code" href="structb2_vec3.html#a12a1bc14bbe722dfb175a492d2d00a79">00167</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec3.html#a12a1bc14bbe722dfb175a492d2d00a79" title="Set this vector to some specified coordinates.">Set</a>(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
<a name="l00168"></a>00168 
<a name="l00170"></a><a class="code" href="structb2_vec3.html#a246cb7ed59d3e758989939ed4e30e5ec">00170</a>         <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> <a class="code" href="structb2_vec3.html#a246cb7ed59d3e758989939ed4e30e5ec" title="Negate this vector.">operator -</a>()<span class="keyword"> const </span>{ <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> v; v.<a class="code" href="structb2_vec3.html#a12a1bc14bbe722dfb175a492d2d00a79" title="Set this vector to some specified coordinates.">Set</a>(-x, -y, -z); <span class="keywordflow">return</span> v; }
<a name="l00171"></a>00171 
<a name="l00173"></a><a class="code" href="structb2_vec3.html#a2aaeed3f5308aad85d19c5f0efc72641">00173</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec3.html#a2aaeed3f5308aad85d19c5f0efc72641" title="Add a vector to this vector.">operator += </a>(<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; v)
<a name="l00174"></a>00174         {
<a name="l00175"></a>00175                 x += v.x; y += v.y; z += v.z;
<a name="l00176"></a>00176         }
<a name="l00177"></a>00177 
<a name="l00179"></a><a class="code" href="structb2_vec3.html#a9e5b535548e1c5dfc0dc258d08f5ca32">00179</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec3.html#a9e5b535548e1c5dfc0dc258d08f5ca32" title="Subtract a vector from this vector.">operator -= </a>(<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; v)
<a name="l00180"></a>00180         {
<a name="l00181"></a>00181                 x -= v.x; y -= v.y; z -= v.z;
<a name="l00182"></a>00182         }
<a name="l00183"></a>00183 
<a name="l00185"></a><a class="code" href="structb2_vec3.html#aaa9aa20195cd0ee53c7176a9a9b02389">00185</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_vec3.html#aaa9aa20195cd0ee53c7176a9a9b02389" title="Multiply this vector by a scalar.">operator *= </a>(float32 s)
<a name="l00186"></a>00186         {
<a name="l00187"></a>00187                 x *= s; y *= s; z *= s;
<a name="l00188"></a>00188         }
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         float32 x, y, z;
<a name="l00191"></a>00191 };
<a name="l00192"></a>00192 
<a name="l00194"></a><a class="code" href="structb2_mat22.html">00194</a> <span class="keyword">struct </span><a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>
<a name="l00195"></a>00195 {
<a name="l00197"></a><a class="code" href="structb2_mat22.html#ac3e10f6d457c8dab9062ba378f66bc4d">00197</a>         <a class="code" href="structb2_mat22.html#ac3e10f6d457c8dab9062ba378f66bc4d" title="The default constructor does nothing (for performance).">b2Mat22</a>() {}
<a name="l00198"></a>00198 
<a name="l00200"></a><a class="code" href="structb2_mat22.html#abd674c6d92e26962977f34bcd92ff24d">00200</a>         <a class="code" href="structb2_mat22.html#ac3e10f6d457c8dab9062ba378f66bc4d" title="The default constructor does nothing (for performance).">b2Mat22</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; c1, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; c2)
<a name="l00201"></a>00201         {
<a name="l00202"></a>00202                 ex = c1;
<a name="l00203"></a>00203                 ey = c2;
<a name="l00204"></a>00204         }
<a name="l00205"></a>00205 
<a name="l00207"></a><a class="code" href="structb2_mat22.html#a41d5d8743bda32cb8c6e212528934810">00207</a>         <a class="code" href="structb2_mat22.html#ac3e10f6d457c8dab9062ba378f66bc4d" title="The default constructor does nothing (for performance).">b2Mat22</a>(float32 a11, float32 a12, float32 a21, float32 a22)
<a name="l00208"></a>00208         {
<a name="l00209"></a>00209                 ex.x = a11; ex.y = a21;
<a name="l00210"></a>00210                 ey.x = a12; ey.y = a22;
<a name="l00211"></a>00211         }
<a name="l00212"></a>00212 
<a name="l00214"></a><a class="code" href="structb2_mat22.html#aed3bee1de38a0b3f36e21c90faa24112">00214</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_mat22.html#aed3bee1de38a0b3f36e21c90faa24112" title="Initialize this matrix using columns.">Set</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; c1, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; c2)
<a name="l00215"></a>00215         {
<a name="l00216"></a>00216                 ex = c1;
<a name="l00217"></a>00217                 ey = c2;
<a name="l00218"></a>00218         }
<a name="l00219"></a>00219 
<a name="l00221"></a><a class="code" href="structb2_mat22.html#a7192f063b771ac9ded060e41df890509">00221</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_mat22.html#a7192f063b771ac9ded060e41df890509" title="Set this to the identity matrix.">SetIdentity</a>()
<a name="l00222"></a>00222         {
<a name="l00223"></a>00223                 ex.x = 1.0f; ey.x = 0.0f;
<a name="l00224"></a>00224                 ex.y = 0.0f; ey.y = 1.0f;
<a name="l00225"></a>00225         }
<a name="l00226"></a>00226 
<a name="l00228"></a><a class="code" href="structb2_mat22.html#aaeae95f61cf3171ffb94703980e3594b">00228</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_mat22.html#aaeae95f61cf3171ffb94703980e3594b" title="Set this matrix to all zeros.">SetZero</a>()
<a name="l00229"></a>00229         {
<a name="l00230"></a>00230                 ex.x = 0.0f; ey.x = 0.0f;
<a name="l00231"></a>00231                 ex.y = 0.0f; ey.y = 0.0f;
<a name="l00232"></a>00232         }
<a name="l00233"></a>00233 
<a name="l00234"></a>00234         <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a> GetInverse()<span class="keyword"> const</span>
<a name="l00235"></a>00235 <span class="keyword">        </span>{
<a name="l00236"></a>00236                 float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
<a name="l00237"></a>00237                 <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a> B;
<a name="l00238"></a>00238                 float32 det = a * d - b * c;
<a name="l00239"></a>00239                 <span class="keywordflow">if</span> (det != 0.0f)
<a name="l00240"></a>00240                 {
<a name="l00241"></a>00241                         det = 1.0f / det;
<a name="l00242"></a>00242                 }
<a name="l00243"></a>00243                 B.ex.x =  det * d;      B.ey.x = -det * b;
<a name="l00244"></a>00244                 B.ex.y = -det * c;      B.ey.y =  det * a;
<a name="l00245"></a>00245                 <span class="keywordflow">return</span> B;
<a name="l00246"></a>00246         }
<a name="l00247"></a>00247 
<a name="l00250"></a><a class="code" href="structb2_mat22.html#ab511ad33f5abf87351581842628a9dc3">00250</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_mat22.html#ab511ad33f5abf87351581842628a9dc3">Solve</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)<span class="keyword"> const</span>
<a name="l00251"></a>00251 <span class="keyword">        </span>{
<a name="l00252"></a>00252                 float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
<a name="l00253"></a>00253                 float32 det = a11 * a22 - a12 * a21;
<a name="l00254"></a>00254                 <span class="keywordflow">if</span> (det != 0.0f)
<a name="l00255"></a>00255                 {
<a name="l00256"></a>00256                         det = 1.0f / det;
<a name="l00257"></a>00257                 }
<a name="l00258"></a>00258                 <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> x;
<a name="l00259"></a>00259                 x.x = det * (a22 * b.x - a12 * b.y);
<a name="l00260"></a>00260                 x.y = det * (a11 * b.y - a21 * b.x);
<a name="l00261"></a>00261                 <span class="keywordflow">return</span> x;
<a name="l00262"></a>00262         }
<a name="l00263"></a>00263 
<a name="l00264"></a>00264         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> ex, ey;
<a name="l00265"></a>00265 };
<a name="l00266"></a>00266 
<a name="l00268"></a><a class="code" href="structb2_mat33.html">00268</a> <span class="keyword">struct </span><a class="code" href="structb2_mat33.html" title="A 3-by-3 matrix. Stored in column-major order.">b2Mat33</a>
<a name="l00269"></a>00269 {
<a name="l00271"></a><a class="code" href="structb2_mat33.html#a1f4d7ddf1c8a202fc08ec64dfe191463">00271</a>         <a class="code" href="structb2_mat33.html#a1f4d7ddf1c8a202fc08ec64dfe191463" title="The default constructor does nothing (for performance).">b2Mat33</a>() {}
<a name="l00272"></a>00272 
<a name="l00274"></a><a class="code" href="structb2_mat33.html#a36d99a037008776c8d09fe0aeb5c759c">00274</a>         <a class="code" href="structb2_mat33.html#a1f4d7ddf1c8a202fc08ec64dfe191463" title="The default constructor does nothing (for performance).">b2Mat33</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; c1, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; c2, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; c3)
<a name="l00275"></a>00275         {
<a name="l00276"></a>00276                 ex = c1;
<a name="l00277"></a>00277                 ey = c2;
<a name="l00278"></a>00278                 ez = c3;
<a name="l00279"></a>00279         }
<a name="l00280"></a>00280 
<a name="l00282"></a><a class="code" href="structb2_mat33.html#a42fc6953b025e1c8b59717d0ee7accde">00282</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_mat33.html#a42fc6953b025e1c8b59717d0ee7accde" title="Set this matrix to all zeros.">SetZero</a>()
<a name="l00283"></a>00283         {
<a name="l00284"></a>00284                 ex.<a class="code" href="structb2_vec3.html#a5a459ed49f1910a347ca247f848a2dd8" title="Set this vector to all zeros.">SetZero</a>();
<a name="l00285"></a>00285                 ey.<a class="code" href="structb2_vec3.html#a5a459ed49f1910a347ca247f848a2dd8" title="Set this vector to all zeros.">SetZero</a>();
<a name="l00286"></a>00286                 ez.<a class="code" href="structb2_vec3.html#a5a459ed49f1910a347ca247f848a2dd8" title="Set this vector to all zeros.">SetZero</a>();
<a name="l00287"></a>00287         }
<a name="l00288"></a>00288 
<a name="l00291"></a>00291         <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> <a class="code" href="structb2_mat33.html#a478872c7b6a3bedd13fbedd3ec7a2edb">Solve33</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; b) <span class="keyword">const</span>;
<a name="l00292"></a>00292 
<a name="l00296"></a>00296         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_mat33.html#a2580ac2afadc48028a63ed4c8a1f16bc">Solve22</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b) <span class="keyword">const</span>;
<a name="l00297"></a>00297 
<a name="l00300"></a>00300         <span class="keywordtype">void</span> <a class="code" href="structb2_mat33.html#a9eb5090b15d08ab495458adfec50e7cb">GetInverse22</a>(<a class="code" href="structb2_mat33.html" title="A 3-by-3 matrix. Stored in column-major order.">b2Mat33</a>* M) <span class="keyword">const</span>;
<a name="l00301"></a>00301 
<a name="l00304"></a>00304         <span class="keywordtype">void</span> <a class="code" href="structb2_mat33.html#a501f85edde8f080e4e9ecff0ec2ee27e" title="Returns the zero matrix if singular.">GetSymInverse33</a>(<a class="code" href="structb2_mat33.html" title="A 3-by-3 matrix. Stored in column-major order.">b2Mat33</a>* M) <span class="keyword">const</span>;
<a name="l00305"></a>00305 
<a name="l00306"></a>00306         <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> ex, ey, ez;
<a name="l00307"></a>00307 };
<a name="l00308"></a>00308 
<a name="l00310"></a><a class="code" href="structb2_rot.html">00310</a> <span class="keyword">struct </span><a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>
<a name="l00311"></a>00311 {
<a name="l00312"></a>00312         <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>() {}
<a name="l00313"></a>00313 
<a name="l00315"></a><a class="code" href="structb2_rot.html#aa40dda6d390a2f54c793c63027a9b46e">00315</a>         <span class="keyword">explicit</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>(float32 angle)
<a name="l00316"></a>00316         {
<a name="l00318"></a>00318                 <a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> = sinf(angle);
<a name="l00319"></a>00319                 c = cosf(angle);
<a name="l00320"></a>00320         }
<a name="l00321"></a>00321 
<a name="l00323"></a><a class="code" href="structb2_rot.html#acde9186de0a4a7397bf8ef714408ad60">00323</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_rot.html#acde9186de0a4a7397bf8ef714408ad60" title="Set using an angle in radians.">Set</a>(float32 angle)
<a name="l00324"></a>00324         {
<a name="l00326"></a>00326                 <a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> = sinf(angle);
<a name="l00327"></a>00327                 c = cosf(angle);
<a name="l00328"></a>00328         }
<a name="l00329"></a>00329 
<a name="l00331"></a><a class="code" href="structb2_rot.html#a7f534cb7ece8d325662d7d0e27d4f617">00331</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_rot.html#a7f534cb7ece8d325662d7d0e27d4f617" title="Set to the identity rotation.">SetIdentity</a>()
<a name="l00332"></a>00332         {
<a name="l00333"></a>00333                 <a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> = 0.0f;
<a name="l00334"></a>00334                 c = 1.0f;
<a name="l00335"></a>00335         }
<a name="l00336"></a>00336 
<a name="l00338"></a><a class="code" href="structb2_rot.html#a67a6c08812c009654f00800256c8bfdc">00338</a>         float32 <a class="code" href="structb2_rot.html#a67a6c08812c009654f00800256c8bfdc" title="Get the angle in radians.">GetAngle</a>()<span class="keyword"> const</span>
<a name="l00339"></a>00339 <span class="keyword">        </span>{
<a name="l00340"></a>00340                 <span class="keywordflow">return</span> b2Atan2(<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>, c);
<a name="l00341"></a>00341         }
<a name="l00342"></a>00342 
<a name="l00344"></a><a class="code" href="structb2_rot.html#ac4ab7f262adb99f161775314852723d8">00344</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_rot.html#ac4ab7f262adb99f161775314852723d8" title="Get the x-axis.">GetXAxis</a>()<span class="keyword"> const</span>
<a name="l00345"></a>00345 <span class="keyword">        </span>{
<a name="l00346"></a>00346                 <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(c, <a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>);
<a name="l00347"></a>00347         }
<a name="l00348"></a>00348 
<a name="l00350"></a><a class="code" href="structb2_rot.html#ae731c7434fe1754114ee70149df36c7f">00350</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_rot.html#ae731c7434fe1754114ee70149df36c7f" title="Get the u-axis.">GetYAxis</a>()<span class="keyword"> const</span>
<a name="l00351"></a>00351 <span class="keyword">        </span>{
<a name="l00352"></a>00352                 <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(-<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>, c);
<a name="l00353"></a>00353         }
<a name="l00354"></a>00354 
<a name="l00356"></a><a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce">00356</a>         float32 <a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>, c;
<a name="l00357"></a>00357 };
<a name="l00358"></a>00358 
<a name="l00361"></a><a class="code" href="structb2_transform.html">00361</a> <span class="keyword">struct </span><a class="code" href="structb2_transform.html">b2Transform</a>
<a name="l00362"></a>00362 {
<a name="l00364"></a><a class="code" href="structb2_transform.html#a765a2e5c692a2e1d05c7a5441019373d">00364</a>         <a class="code" href="structb2_transform.html#a765a2e5c692a2e1d05c7a5441019373d" title="The default constructor does nothing.">b2Transform</a>() {}
<a name="l00365"></a>00365 
<a name="l00367"></a><a class="code" href="structb2_transform.html#a823e190e4810e35e8100f4414d0bef62">00367</a>         <a class="code" href="structb2_transform.html#a823e190e4810e35e8100f4414d0bef62" title="Initialize using a position vector and a rotation.">b2Transform</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; position, <span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; rotation) : p(position), q(rotation) {}
<a name="l00368"></a>00368 
<a name="l00370"></a><a class="code" href="structb2_transform.html#af92af4ec6833552b1b22a6ca6d4f5644">00370</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_transform.html#af92af4ec6833552b1b22a6ca6d4f5644" title="Set this to the identity transform.">SetIdentity</a>()
<a name="l00371"></a>00371         {
<a name="l00372"></a>00372                 p.<a class="code" href="structb2_vec2.html#a5c6cbe27cfb29c6dbb29b9a3285b88d0" title="Set this vector to all zeros.">SetZero</a>();
<a name="l00373"></a>00373                 q.<a class="code" href="structb2_rot.html#a7f534cb7ece8d325662d7d0e27d4f617" title="Set to the identity rotation.">SetIdentity</a>();
<a name="l00374"></a>00374         }
<a name="l00375"></a>00375 
<a name="l00377"></a><a class="code" href="structb2_transform.html#a4db696a0b3fada95f95cde3e7e85ced9">00377</a>         <span class="keywordtype">void</span> <a class="code" href="structb2_transform.html#a4db696a0b3fada95f95cde3e7e85ced9" title="Set this based on the position and angle.">Set</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; position, float32 angle)
<a name="l00378"></a>00378         {
<a name="l00379"></a>00379                 p = position;
<a name="l00380"></a>00380                 q.<a class="code" href="structb2_rot.html#acde9186de0a4a7397bf8ef714408ad60" title="Set using an angle in radians.">Set</a>(angle);
<a name="l00381"></a>00381         }
<a name="l00382"></a>00382 
<a name="l00383"></a>00383         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> p;
<a name="l00384"></a>00384         <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a> q;
<a name="l00385"></a>00385 };
<a name="l00386"></a>00386 
<a name="l00391"></a><a class="code" href="structb2_sweep.html">00391</a> <span class="keyword">struct </span><a class="code" href="structb2_sweep.html">b2Sweep</a>
<a name="l00392"></a>00392 {
<a name="l00395"></a>00395         <span class="keywordtype">void</span> <a class="code" href="structb2_sweep.html#a81947646092468290d15005928e12fcd">GetTransform</a>(<a class="code" href="structb2_transform.html">b2Transform</a>* xfb, float32 beta) <span class="keyword">const</span>;
<a name="l00396"></a>00396 
<a name="l00399"></a>00399         <span class="keywordtype">void</span> <a class="code" href="structb2_sweep.html#a35eb9b976ca87c9b8d758bec070c6c06">Advance</a>(float32 alpha);
<a name="l00400"></a>00400 
<a name="l00402"></a>00402         <span class="keywordtype">void</span> <a class="code" href="structb2_sweep.html#ad66a3086bc7656df9cf7454013a2f61b" title="Normalize the angles.">Normalize</a>();
<a name="l00403"></a>00403 
<a name="l00404"></a><a class="code" href="structb2_sweep.html#a4bcc302cf78771896d6256fc53f2f8be">00404</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> <a class="code" href="structb2_sweep.html#a4bcc302cf78771896d6256fc53f2f8be" title="local center of mass position">localCenter</a>;     
<a name="l00405"></a><a class="code" href="structb2_sweep.html#a1b5402e01b92cc82473389fc6f0375c3">00405</a>         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> c0, <a class="code" href="structb2_sweep.html#a1b5402e01b92cc82473389fc6f0375c3" title="center world positions">c</a>;           
<a name="l00406"></a><a class="code" href="structb2_sweep.html#afa96bacc91dd3c92ae716a45512332d6">00406</a>         float32 a0, <a class="code" href="structb2_sweep.html#afa96bacc91dd3c92ae716a45512332d6" title="world angles">a</a>;          
<a name="l00407"></a>00407 
<a name="l00410"></a><a class="code" href="structb2_sweep.html#aa5f8ab90178b58bc0777096cbc6b91cf">00410</a>         float32 <a class="code" href="structb2_sweep.html#aa5f8ab90178b58bc0777096cbc6b91cf">alpha0</a>;
<a name="l00411"></a>00411 };
<a name="l00412"></a>00412 
<a name="l00414"></a>00414 <span class="keyword">extern</span> <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Vec2_zero;
<a name="l00415"></a>00415 
<a name="l00417"></a>00417 <span class="keyword">inline</span> float32 b2Dot(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00418"></a>00418 {
<a name="l00419"></a>00419         <span class="keywordflow">return</span> a.x * b.x + a.y * b.y;
<a name="l00420"></a>00420 }
<a name="l00421"></a>00421 
<a name="l00423"></a>00423 <span class="keyword">inline</span> float32 b2Cross(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00424"></a>00424 {
<a name="l00425"></a>00425         <span class="keywordflow">return</span> a.x * b.y - a.y * b.x;
<a name="l00426"></a>00426 }
<a name="l00427"></a>00427 
<a name="l00430"></a>00430 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Cross(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, float32 s)
<a name="l00431"></a>00431 {
<a name="l00432"></a>00432         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(s * a.y, -s * a.x);
<a name="l00433"></a>00433 }
<a name="l00434"></a>00434 
<a name="l00437"></a>00437 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Cross(float32 s, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a)
<a name="l00438"></a>00438 {
<a name="l00439"></a>00439         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(-s * a.y, s * a.x);
<a name="l00440"></a>00440 }
<a name="l00441"></a>00441 
<a name="l00444"></a>00444 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00445"></a>00445 {
<a name="l00446"></a>00446         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
<a name="l00447"></a>00447 }
<a name="l00448"></a>00448 
<a name="l00451"></a>00451 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2MulT(<span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00452"></a>00452 {
<a name="l00453"></a>00453         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(b2Dot(v, A.ex), b2Dot(v, A.ey));
<a name="l00454"></a>00454 }
<a name="l00455"></a>00455 
<a name="l00457"></a>00457 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> operator + (<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00458"></a>00458 {
<a name="l00459"></a>00459         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(a.x + b.x, a.y + b.y);
<a name="l00460"></a>00460 }
<a name="l00461"></a>00461 
<a name="l00463"></a>00463 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> operator - (<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00464"></a>00464 {
<a name="l00465"></a>00465         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(a.x - b.x, a.y - b.y);
<a name="l00466"></a>00466 }
<a name="l00467"></a>00467 
<a name="l00468"></a>00468 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> operator * (float32 s, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a)
<a name="l00469"></a>00469 {
<a name="l00470"></a>00470         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(s * a.x, s * a.y);
<a name="l00471"></a>00471 }
<a name="l00472"></a>00472 
<a name="l00473"></a>00473 <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator == (<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00474"></a>00474 {
<a name="l00475"></a>00475         <span class="keywordflow">return</span> a.x == b.x &amp;&amp; a.y == b.y;
<a name="l00476"></a>00476 }
<a name="l00477"></a>00477 
<a name="l00478"></a>00478 <span class="keyword">inline</span> float32 b2Distance(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00479"></a>00479 {
<a name="l00480"></a>00480         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> c = a - b;
<a name="l00481"></a>00481         <span class="keywordflow">return</span> c.<a class="code" href="structb2_vec2.html#afb1c498214b88874fcb07eb6322374da" title="Get the length of this vector (the norm).">Length</a>();
<a name="l00482"></a>00482 }
<a name="l00483"></a>00483 
<a name="l00484"></a>00484 <span class="keyword">inline</span> float32 b2DistanceSquared(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00485"></a>00485 {
<a name="l00486"></a>00486         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> c = a - b;
<a name="l00487"></a>00487         <span class="keywordflow">return</span> b2Dot(c, c);
<a name="l00488"></a>00488 }
<a name="l00489"></a>00489 
<a name="l00490"></a>00490 <span class="keyword">inline</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> operator * (float32 s, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; a)
<a name="l00491"></a>00491 {
<a name="l00492"></a>00492         <span class="keywordflow">return</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>(s * a.x, s * a.y, s * a.z);
<a name="l00493"></a>00493 }
<a name="l00494"></a>00494 
<a name="l00496"></a>00496 <span class="keyword">inline</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> operator + (<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; b)
<a name="l00497"></a>00497 {
<a name="l00498"></a>00498         <span class="keywordflow">return</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>(a.x + b.x, a.y + b.y, a.z + b.z);
<a name="l00499"></a>00499 }
<a name="l00500"></a>00500 
<a name="l00502"></a>00502 <span class="keyword">inline</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> operator - (<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; b)
<a name="l00503"></a>00503 {
<a name="l00504"></a>00504         <span class="keywordflow">return</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>(a.x - b.x, a.y - b.y, a.z - b.z);
<a name="l00505"></a>00505 }
<a name="l00506"></a>00506 
<a name="l00508"></a>00508 <span class="keyword">inline</span> float32 b2Dot(<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; b)
<a name="l00509"></a>00509 {
<a name="l00510"></a>00510         <span class="keywordflow">return</span> a.x * b.x + a.y * b.y + a.z * b.z;
<a name="l00511"></a>00511 }
<a name="l00512"></a>00512 
<a name="l00514"></a>00514 <span class="keyword">inline</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> b2Cross(<span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; b)
<a name="l00515"></a>00515 {
<a name="l00516"></a>00516         <span class="keywordflow">return</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
<a name="l00517"></a>00517 }
<a name="l00518"></a>00518 
<a name="l00519"></a>00519 <span class="keyword">inline</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a> operator + (<span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; B)
<a name="l00520"></a>00520 {
<a name="l00521"></a>00521         <span class="keywordflow">return</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>(A.ex + B.ex, A.ey + B.ey);
<a name="l00522"></a>00522 }
<a name="l00523"></a>00523 
<a name="l00524"></a>00524 <span class="comment">// A * B</span>
<a name="l00525"></a>00525 <span class="keyword">inline</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; B)
<a name="l00526"></a>00526 {
<a name="l00527"></a>00527         <span class="keywordflow">return</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>(b2Mul(A, B.ex), b2Mul(A, B.ey));
<a name="l00528"></a>00528 }
<a name="l00529"></a>00529 
<a name="l00530"></a>00530 <span class="comment">// A^T * B</span>
<a name="l00531"></a>00531 <span class="keyword">inline</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a> b2MulT(<span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; B)
<a name="l00532"></a>00532 {
<a name="l00533"></a>00533         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
<a name="l00534"></a>00534         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
<a name="l00535"></a>00535         <span class="keywordflow">return</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>(c1, c2);
<a name="l00536"></a>00536 }
<a name="l00537"></a>00537 
<a name="l00539"></a>00539 <span class="keyword">inline</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_mat33.html" title="A 3-by-3 matrix. Stored in column-major order.">b2Mat33</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_vec3.html" title="A 2D column vector with 3 elements.">b2Vec3</a>&amp; v)
<a name="l00540"></a>00540 {
<a name="l00541"></a>00541         <span class="keywordflow">return</span> v.x * A.ex + v.y * A.ey + v.z * A.ez;
<a name="l00542"></a>00542 }
<a name="l00543"></a>00543 
<a name="l00545"></a>00545 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Mul22(<span class="keyword">const</span> <a class="code" href="structb2_mat33.html" title="A 3-by-3 matrix. Stored in column-major order.">b2Mat33</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00546"></a>00546 {
<a name="l00547"></a>00547         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
<a name="l00548"></a>00548 }
<a name="l00549"></a>00549 
<a name="l00551"></a>00551 <span class="keyword">inline</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; q, <span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; r)
<a name="l00552"></a>00552 {
<a name="l00553"></a>00553         <span class="comment">// [qc -qs] * [rc -rs] = [qc*rc-qs*rs -qc*rs-qs*rc]</span>
<a name="l00554"></a>00554         <span class="comment">// [qs  qc]   [rs  rc]   [qs*rc+qc*rs -qs*rs+qc*rc]</span>
<a name="l00555"></a>00555         <span class="comment">// s = qs * rc + qc * rs</span>
<a name="l00556"></a>00556         <span class="comment">// c = qc * rc - qs * rs</span>
<a name="l00557"></a>00557         <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a> qr;
<a name="l00558"></a>00558         qr.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> = q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * r.c + q.c * r.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>;
<a name="l00559"></a>00559         qr.c = q.c * r.c - q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * r.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>;
<a name="l00560"></a>00560         <span class="keywordflow">return</span> qr;
<a name="l00561"></a>00561 }
<a name="l00562"></a>00562 
<a name="l00564"></a>00564 <span class="keyword">inline</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a> b2MulT(<span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; q, <span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; r)
<a name="l00565"></a>00565 {
<a name="l00566"></a>00566         <span class="comment">// [ qc qs] * [rc -rs] = [qc*rc+qs*rs -qc*rs+qs*rc]</span>
<a name="l00567"></a>00567         <span class="comment">// [-qs qc]   [rs  rc]   [-qs*rc+qc*rs qs*rs+qc*rc]</span>
<a name="l00568"></a>00568         <span class="comment">// s = qc * rs - qs * rc</span>
<a name="l00569"></a>00569         <span class="comment">// c = qc * rc + qs * rs</span>
<a name="l00570"></a>00570         <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a> qr;
<a name="l00571"></a>00571         qr.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> = q.c * r.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> - q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * r.c;
<a name="l00572"></a>00572         qr.c = q.c * r.c + q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * r.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a>;
<a name="l00573"></a>00573         <span class="keywordflow">return</span> qr;
<a name="l00574"></a>00574 }
<a name="l00575"></a>00575 
<a name="l00577"></a>00577 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; q, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00578"></a>00578 {
<a name="l00579"></a>00579         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(q.c * v.x - q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * v.y, q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * v.x + q.c * v.y);
<a name="l00580"></a>00580 }
<a name="l00581"></a>00581 
<a name="l00583"></a>00583 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2MulT(<span class="keyword">const</span> <a class="code" href="structb2_rot.html" title="Rotation.">b2Rot</a>&amp; q, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00584"></a>00584 {
<a name="l00585"></a>00585         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(q.c * v.x + q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * v.y, -q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * v.x + q.c * v.y);
<a name="l00586"></a>00586 }
<a name="l00587"></a>00587 
<a name="l00588"></a>00588 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_transform.html">b2Transform</a>&amp; T, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00589"></a>00589 {
<a name="l00590"></a>00590         float32 x = (T.q.c * v.x - T.q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * v.y) + T.p.x;
<a name="l00591"></a>00591         float32 y = (T.q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * v.x + T.q.c * v.y) + T.p.y;
<a name="l00592"></a>00592 
<a name="l00593"></a>00593         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(x, y);
<a name="l00594"></a>00594 }
<a name="l00595"></a>00595 
<a name="l00596"></a>00596 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2MulT(<span class="keyword">const</span> <a class="code" href="structb2_transform.html">b2Transform</a>&amp; T, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; v)
<a name="l00597"></a>00597 {
<a name="l00598"></a>00598         float32 px = v.x - T.p.x;
<a name="l00599"></a>00599         float32 py = v.y - T.p.y;
<a name="l00600"></a>00600         float32 x = (T.q.c * px + T.q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * py);
<a name="l00601"></a>00601         float32 y = (-T.q.<a class="code" href="structb2_rot.html#a15725ce0a89cc735ad90687b4c0f4dce" title="Sine and cosine.">s</a> * px + T.q.c * py);
<a name="l00602"></a>00602 
<a name="l00603"></a>00603         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(x, y);
<a name="l00604"></a>00604 }
<a name="l00605"></a>00605 
<a name="l00606"></a>00606 <span class="comment">// v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p</span>
<a name="l00607"></a>00607 <span class="comment">//    = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p</span>
<a name="l00608"></a>00608 <span class="keyword">inline</span> <a class="code" href="structb2_transform.html">b2Transform</a> b2Mul(<span class="keyword">const</span> <a class="code" href="structb2_transform.html">b2Transform</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_transform.html">b2Transform</a>&amp; B)
<a name="l00609"></a>00609 {
<a name="l00610"></a>00610         <a class="code" href="structb2_transform.html">b2Transform</a> C;
<a name="l00611"></a>00611         C.q = b2Mul(A.q, B.q);
<a name="l00612"></a>00612         C.p = b2Mul(A.q, B.p) + A.p;
<a name="l00613"></a>00613         <span class="keywordflow">return</span> C;
<a name="l00614"></a>00614 }
<a name="l00615"></a>00615 
<a name="l00616"></a>00616 <span class="comment">// v2 = A.q&#39; * (B.q * v1 + B.p - A.p)</span>
<a name="l00617"></a>00617 <span class="comment">//    = A.q&#39; * B.q * v1 + A.q&#39; * (B.p - A.p)</span>
<a name="l00618"></a>00618 <span class="keyword">inline</span> <a class="code" href="structb2_transform.html">b2Transform</a> b2MulT(<span class="keyword">const</span> <a class="code" href="structb2_transform.html">b2Transform</a>&amp; A, <span class="keyword">const</span> <a class="code" href="structb2_transform.html">b2Transform</a>&amp; B)
<a name="l00619"></a>00619 {
<a name="l00620"></a>00620         <a class="code" href="structb2_transform.html">b2Transform</a> C;
<a name="l00621"></a>00621         C.q = b2MulT(A.q, B.q);
<a name="l00622"></a>00622         C.p = b2MulT(A.q, B.p - A.p);
<a name="l00623"></a>00623         <span class="keywordflow">return</span> C;
<a name="l00624"></a>00624 }
<a name="l00625"></a>00625 
<a name="l00626"></a>00626 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00627"></a>00627 <span class="keyword">inline</span> T b2Abs(T a)
<a name="l00628"></a>00628 {
<a name="l00629"></a>00629         <span class="keywordflow">return</span> a &gt; T(0) ? a : -a;
<a name="l00630"></a>00630 }
<a name="l00631"></a>00631 
<a name="l00632"></a>00632 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Abs(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a)
<a name="l00633"></a>00633 {
<a name="l00634"></a>00634         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(b2Abs(a.x), b2Abs(a.y));
<a name="l00635"></a>00635 }
<a name="l00636"></a>00636 
<a name="l00637"></a>00637 <span class="keyword">inline</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a> b2Abs(<span class="keyword">const</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>&amp; A)
<a name="l00638"></a>00638 {
<a name="l00639"></a>00639         <span class="keywordflow">return</span> <a class="code" href="structb2_mat22.html" title="A 2-by-2 matrix. Stored in column-major order.">b2Mat22</a>(b2Abs(A.ex), b2Abs(A.ey));
<a name="l00640"></a>00640 }
<a name="l00641"></a>00641 
<a name="l00642"></a>00642 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00643"></a>00643 <span class="keyword">inline</span> T b2Min(T a, T b)
<a name="l00644"></a>00644 {
<a name="l00645"></a>00645         <span class="keywordflow">return</span> a &lt; b ? a : b;
<a name="l00646"></a>00646 }
<a name="l00647"></a>00647 
<a name="l00648"></a>00648 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Min(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00649"></a>00649 {
<a name="l00650"></a>00650         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(b2Min(a.x, b.x), b2Min(a.y, b.y));
<a name="l00651"></a>00651 }
<a name="l00652"></a>00652 
<a name="l00653"></a>00653 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00654"></a>00654 <span class="keyword">inline</span> T b2Max(T a, T b)
<a name="l00655"></a>00655 {
<a name="l00656"></a>00656         <span class="keywordflow">return</span> a &gt; b ? a : b;
<a name="l00657"></a>00657 }
<a name="l00658"></a>00658 
<a name="l00659"></a>00659 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Max(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; b)
<a name="l00660"></a>00660 {
<a name="l00661"></a>00661         <span class="keywordflow">return</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>(b2Max(a.x, b.x), b2Max(a.y, b.y));
<a name="l00662"></a>00662 }
<a name="l00663"></a>00663 
<a name="l00664"></a>00664 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00665"></a>00665 <span class="keyword">inline</span> T b2Clamp(T a, T low, T high)
<a name="l00666"></a>00666 {
<a name="l00667"></a>00667         <span class="keywordflow">return</span> b2Max(low, b2Min(a, high));
<a name="l00668"></a>00668 }
<a name="l00669"></a>00669 
<a name="l00670"></a>00670 <span class="keyword">inline</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> b2Clamp(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; a, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; low, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; high)
<a name="l00671"></a>00671 {
<a name="l00672"></a>00672         <span class="keywordflow">return</span> b2Max(low, b2Min(a, high));
<a name="l00673"></a>00673 }
<a name="l00674"></a>00674 
<a name="l00675"></a>00675 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt; <span class="keyword">inline</span> <span class="keywordtype">void</span> b2Swap(T&amp; a, T&amp; b)
<a name="l00676"></a>00676 {
<a name="l00677"></a>00677         T tmp = a;
<a name="l00678"></a>00678         a = b;
<a name="l00679"></a>00679         b = tmp;
<a name="l00680"></a>00680 }
<a name="l00681"></a>00681 
<a name="l00687"></a>00687 <span class="keyword">inline</span> uint32 b2NextPowerOfTwo(uint32 x)
<a name="l00688"></a>00688 {
<a name="l00689"></a>00689         x |= (x &gt;&gt; 1);
<a name="l00690"></a>00690         x |= (x &gt;&gt; 2);
<a name="l00691"></a>00691         x |= (x &gt;&gt; 4);
<a name="l00692"></a>00692         x |= (x &gt;&gt; 8);
<a name="l00693"></a>00693         x |= (x &gt;&gt; 16);
<a name="l00694"></a>00694         <span class="keywordflow">return</span> x + 1;
<a name="l00695"></a>00695 }
<a name="l00696"></a>00696 
<a name="l00697"></a>00697 <span class="keyword">inline</span> <span class="keywordtype">bool</span> b2IsPowerOfTwo(uint32 x)
<a name="l00698"></a>00698 {
<a name="l00699"></a>00699         <span class="keywordtype">bool</span> result = x &gt; 0 &amp;&amp; (x &amp; (x - 1)) == 0;
<a name="l00700"></a>00700         <span class="keywordflow">return</span> result;
<a name="l00701"></a>00701 }
<a name="l00702"></a>00702 
<a name="l00703"></a><a class="code" href="structb2_sweep.html#a81947646092468290d15005928e12fcd">00703</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structb2_sweep.html#a81947646092468290d15005928e12fcd">b2Sweep::GetTransform</a>(<a class="code" href="structb2_transform.html">b2Transform</a>* xf, float32 beta)<span class="keyword"> const</span>
<a name="l00704"></a>00704 <span class="keyword"></span>{
<a name="l00705"></a>00705         xf-&gt;p = (1.0f - beta) * c0 + beta * c;
<a name="l00706"></a>00706         float32 angle = (1.0f - beta) * a0 + beta * a;
<a name="l00707"></a>00707         xf-&gt;q.<a class="code" href="structb2_rot.html#acde9186de0a4a7397bf8ef714408ad60" title="Set using an angle in radians.">Set</a>(angle);
<a name="l00708"></a>00708 
<a name="l00709"></a>00709         <span class="comment">// Shift to origin</span>
<a name="l00710"></a>00710         xf-&gt;p -= b2Mul(xf-&gt;q, <a class="code" href="structb2_sweep.html#a4bcc302cf78771896d6256fc53f2f8be" title="local center of mass position">localCenter</a>);
<a name="l00711"></a>00711 }
<a name="l00712"></a>00712 
<a name="l00713"></a><a class="code" href="structb2_sweep.html#a35eb9b976ca87c9b8d758bec070c6c06">00713</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structb2_sweep.html#a35eb9b976ca87c9b8d758bec070c6c06">b2Sweep::Advance</a>(float32 alpha)
<a name="l00714"></a>00714 {
<a name="l00715"></a>00715         b2Assert(<a class="code" href="structb2_sweep.html#aa5f8ab90178b58bc0777096cbc6b91cf">alpha0</a> &lt; 1.0f);
<a name="l00716"></a>00716         float32 beta = (alpha - <a class="code" href="structb2_sweep.html#aa5f8ab90178b58bc0777096cbc6b91cf">alpha0</a>) / (1.0f - <a class="code" href="structb2_sweep.html#aa5f8ab90178b58bc0777096cbc6b91cf">alpha0</a>);
<a name="l00717"></a>00717         c0 = (1.0f - beta) * c0 + beta * c;
<a name="l00718"></a>00718         a0 = (1.0f - beta) * a0 + beta * a;
<a name="l00719"></a>00719         <a class="code" href="structb2_sweep.html#aa5f8ab90178b58bc0777096cbc6b91cf">alpha0</a> = alpha;
<a name="l00720"></a>00720 }
<a name="l00721"></a>00721 
<a name="l00723"></a><a class="code" href="structb2_sweep.html#ad66a3086bc7656df9cf7454013a2f61b">00723</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="structb2_sweep.html#ad66a3086bc7656df9cf7454013a2f61b" title="Normalize the angles.">b2Sweep::Normalize</a>()
<a name="l00724"></a>00724 {
<a name="l00725"></a>00725         float32 twoPi = 2.0f * b2_pi;
<a name="l00726"></a>00726         float32 d =  twoPi * floorf(a0 / twoPi);
<a name="l00727"></a>00727         a0 -= d;
<a name="l00728"></a>00728         a -= d;
<a name="l00729"></a>00729 }
<a name="l00730"></a>00730 
<a name="l00731"></a>00731 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sat Sep 17 2011 17:35:55 for Box2D by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
